﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace _02._10.EntityFramework
{
    class Program
    {
        static void Main(string[] args)
        {
            //PrintCustomers();
            //InsertPeterPanInCustomers();
            //PrintCustomers();
            //UpdatePeterPanName();

            //PrintCustomers();

            var customersWithOrdersInCanadaInYear1997 =
                NorthwindDAL.GetCustomersWithOrdersInYearAndCountry_Using_ObjectContext(1997, "Canada");

            foreach (Customer c in customersWithOrdersInCanadaInYear1997)
            {
                Console.WriteLine("{0} {1}", c.CustomerID, c.ContactName);

                //Console.WriteLine(c);
            }
            
        }

        private static void UpdatePeterPanName()
        {
            Customer c = NorthwindDAL.GetCustomerByContactName("Peter Pan");

            if (c == null)
            {
                Console.WriteLine("Not found.");
            }
            else
            {
                Console.WriteLine("Found.");
                Console.WriteLine("{0} {1}", c.CustomerID, c.ContactName);

                c.ContactName = "Peter's XYZ very new name";

                //NorthwindDAL.DeleteCustomer(c);
                NorthwindDAL.UpdateCustomer(c);

                Console.WriteLine("Updated Peter Pan's name.");
            }
        }

        private static void PrintCustomers()
        {
            using (NorthwindEntities context = new NorthwindEntities())
            {
                var customers = context.Customers.OrderBy(c => c.ContactName);

                foreach (Customer customer in customers)
                {
                    Console.WriteLine("{0} {1}", customer.CustomerID, customer.ContactName);
                }
            }
        }

        private static void InsertPeterPanInCustomers()
        {
            Customer peterPan = new Customer()
            {
                Address = "Ulitsa Goshev",
                City = "Sofia",
                CompanyName = "Telerik",
                ContactName = "Peter Pan",
                ContactTitle = "God",
                Country = "Buljaria",
                Phone = "0885 925 687",

            };

            NorthwindDAL.InsertCustomer(peterPan);
        }
    }
}
